import '../css/information.scss'
import '../css/common/header.scss'
import '../css/common/footer.scss'

if (module.hot) { module.hot.accept() } // 实现热更新

setTimeout(()=>{
    console.log('smallOnlineGames');
}, 1000);

// 鼠标hvoer显示图片
(function () {
    var $gift = $('.main-r .hot-game ul li');

    $gift.hover(function () {
        $(this).siblings().removeClass('active');
        $(this).addClass('active');
    })
})();


(function () { // 文本超出隐藏
    var $not = $('.news ul');

    var $span = $not.find('li .right-text .commit span');

    for (let i = 0; i < $span.length; i++) {
        textEllipsis($span.get(i), 2, 520);
    }

    function textEllipsis(ele, line, y) {
        if((ele.currentStyle?ele.currentStyle['position']:getComputedStyle(ele)['position']) === "static") ele.style.position = "relative";
        var str = ele.innerText;
        ele.innerHTML = null;
        var lineSum = 1;
        var strIndex = '';
        var topS = 0;
        var topT = 0;
        for (var i = 0; i < str.length; i++) {
            var eSpan = document.createElement('span');
            strIndex = str.substring(i, i+1);
            eSpan.innerText = strIndex;
            ele.appendChild(eSpan);
            topT = eSpan.offsetTop;
            if (topS !== topT) {topS = topT;lineSum ++;}
            if (lineSum === line && eSpan.offsetLeft + eSpan.offsetWidth >= y) {
                ele.innerHTML = null;
                ele.innerText = (str.substring(0, i)).replace(/.{1,3}$/, '...');
                break
            }
            if (lineSum > line) {
                ele.innerHTML = null;
                ele.innerText = (str.substring(0, i)).replace(/.{1,4}$/, '...');
                return
            }
            if (i === str.length - 1) {
                ele.innerHTML = null;
                ele.innerText = str;
            }
        }
    }
})()
